import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
// 分页组件
import Pagination from '@/components/Pagination/index.vue'
// 自定义表格工具组件
import RightToolbar from '@/components/RightToolbar/index.vue'
import plugins from './plugins/index'

import App from './App.vue'
import router from './router'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import directive from './directive/index.js'
import './assets/main.css'
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/common.js'
import FileUpload from "@/components/FileUpload/index.vue"
import 'default-passive-events'
// 图片预览组件
import ImagePreview from "@/components/ImagePreview/index.vue"
import ImageUpload from "@/components/ImageUpload/index.vue"
import { library } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { fas } from '@fortawesome/free-solid-svg-icons'
import { fab } from '@fortawesome/free-brands-svg-icons'
import * as ELIcons from '@element-plus/icons-vue'
import "font-awesome/css/font-awesome.min.css"
// 富文本组件
import Editor from "@/components/Editor/index.vue"

library.add(fas, fab)


const app = createApp(App)

// 全局方法挂载
app.config.globalProperties.$icons = []
app.config.globalProperties.parseTime = parseTime
app.config.globalProperties.resetForm = resetForm
app.config.globalProperties.handleTree = handleTree
app.config.globalProperties.addDateRange = addDateRange
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels

// 全局组件挂载
app.component('RightToolbar', RightToolbar)
app.component('Pagination', Pagination)
app.component('ImagePreview', ImagePreview)
app.component('ImageUpload', ImageUpload)
app.component('FileUpload', FileUpload)
app.component('font-awesome-icon', FontAwesomeIcon)
app.component('Editor', Editor)


directive(app)

for (const [key, component] of Object.entries(ELIcons)) {
    app.config.globalProperties.$icons.push(key)
    app.component(key, component)
}
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(pinia)
app.use(router)
app.use(plugins)
app.use(ElementPlus, {locale: zhCn})
app.mount('#app')
